<?php

namespace app\model;

use app\dto\PageDto;
use app\Request;
use think\db\BaseQuery;
use think\facade\Db;
use think\model\concern\SoftDelete;

class BaseModel extends \think\Model
{

    use SoftDelete;

    var $id = "";
    protected $convertNameToCamel = true;
    protected $deleteTime = "delete_time";

    protected $autoWriteTimestamp = 'datetime';

    protected $dateFormat = 'Y-m-d H:i:s';


    static function pageList(PageDto $page, BaseQuery $query)
    {
        return $query->page($page->getPageNum(),
            $page->getPageSize()
        );
    }

    public static function onBeforeInsert($obj)
    {
        $request = \request();
        $userInfo = $request->getUserInfo();
        $obj['createUserId'] = $userInfo['id'] ?? '';
        $obj['createUserName'] = $userInfo['username'] ?? '';
        return $obj;
    }

    public static function onBeforeUpdate($obj)
    {
        $request = \request();
        $userInfo = $request->getUserInfo();
        $obj['updateUserId'] = $userInfo['id'] ?? '';
        $obj['updateUserName'] = $userInfo['username'] ?? '';
        return $obj;
    }


}